<?php
// +----------------------------------------------------------------------
// | EtrolPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Author: Author: LJQ <liujiqi@etrol.com> 
// +----------------------------------------------------------------------

namespace app\basic\controller;

use app\common\controller\Admin;
use app\basic\controller\api\Equipe as EquipeApi;
use app\admin\controller\ajax\Library as LibarayAjax;
/**
 * 物资装备管理
 * @package app\rescue
 */
class Equipe  extends Admin

{
    
    protected $api;
    protected $property;
    
	public function _initialize()
	{
		parent::_initialize();
		$this->api = new EquipeApi();
		$this->property = new LibarayAjax();
	}
    /**
     * 首页
     * @return Json/View
     */
   	public function index() {
   	  if(IS_AJAX){
   	  	$equipeList = $this->api->equipeList($this->scope);
   	  	return $equipeList;
   	  }
   	  $enterpriseList = model('Enterprise')->getSelectList($this->scope);
	  $this->assign('enterpriseList',$enterpriseList);
      return $this->fetch();
 	}
 	

 	/**
 	 * 仓库查询
 	 * @return Json
 	 */
 	public function search() {
 		if(IS_AJAX){
 			$equipeList = $this->api->search(input('keyword'),input('enterpriseId'));
 			return $equipeList;
 		}
 	}
 	
 	
 	/**
 	 * 添加仓库
 	 * @return Json/View
 	 */
 	public function add(){
 		if(IS_POST){
 			$data = input('post.');
 			if(isset($data['isValid'])){
 				$data['isValid'] = 1;
 			}else{
 				$data['isValid'] = 0;
 			}
 			return $this->api->add($data);
 		}
 		$enterpriseList = model('Enterprise')->getSelectList($this->scope);
 		$this->assign('enterpriseList',$enterpriseList);
 		$unitList = $this->property->getUnitType()->getData();
 		$this->assign('unitList',$unitList);
 		$materialEquipeType = $this->property->getMaterialEquipeType()->getData();
 		$this->assign('materialEquipeType',$materialEquipeType);
 		return $this->fetch();
 	}
 	
 	/**
 	 * 编辑仓库
 	 * @param string $craftId
 	 * @return Json/View
 	 */
 	public function edit($equipeId = null){
 		if(IS_POST){
 			$data = input('post.');
 			if(isset($data['isValid'])){
 				$data['isValid'] = 1;
 			}else{
 				$data['isValid'] = 0;
 			}
 			return $this->api->edit($data,$equipeId);
 		}
 		$enterpriseList = model('Enterprise')->getSelectList($this->scope);
 		$this->assign('enterpriseList',$enterpriseList);
 		$unitList = $this->property->getUnitType()->getData();
 		$this->assign('unitList',$unitList);
 		$materialEquipeType = $this->property->getMaterialEquipeType()->getData();
 		$this->assign('materialEquipeType',$materialEquipeType);
 		$equipe = model('Equipe')->find($equipeId);
 		$this->assign('info',$equipe);
 		return $this->fetch();
 		
 	}
 	
 	/**
 	 * 删除仓库
 	 * @return Json
 	 */
 	public function del($equipeId = null) {
 		if(IS_AJAX){
 			return $this->api->del($equipeId);
 		}
 	}
 	
 	/**
 	 * 申请审核
 	 * @param string $id
 	 */
 	public function audit($id = null){
 		return $this->api->audit($id);
 	}
}
